package com.mall.server.controller.sms;


import com.mall.model.domain.SmsFlashPromotionProductRelation;
import com.mall.model.vo.CommonPage;
import com.mall.model.vo.CommonResult;
import com.mall.model.vo.SmsFlashPromotionProductRelationVo;
import com.mall.server.service.sms.SmsFlashPromotionRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/flashProductRelation")
public class SmsFlashPromotionRelationController {

    @Autowired
    private SmsFlashPromotionRelationService smsFlashPromotionRelationService;


    /**
     * 分页查询不同场次关联及商品信息
     */
    @GetMapping("/list")
    public CommonResult list(@RequestParam(defaultValue = "1") Integer pageNum
            , @RequestParam(defaultValue = "10") Integer pageSize
            , SmsFlashPromotionProductRelation flashPromotionProductRelation) {

        CommonPage<SmsFlashPromotionProductRelationVo> cp = smsFlashPromotionRelationService.list(pageNum, pageSize, flashPromotionProductRelation);

        return CommonResult.success(cp);

    }

    /**
     * 修改关联信息
     */
    @PostMapping("/update/{id}")
    public CommonResult update(@PathVariable Integer id, @RequestBody SmsFlashPromotionProductRelation relation) {

        smsFlashPromotionRelationService.update(id, relation);

        return CommonResult.success(null);
    }

    /**
     * 删除关联
     */
    @PostMapping("/delete/{id}")
    public CommonResult delete(@PathVariable Integer id) {

        smsFlashPromotionRelationService.delete(id);

        return CommonResult.success(null);
    }

    /**
     * 批量选择商品添加关联
     */
    @PostMapping("/create")
    public CommonResult create(@RequestBody List<SmsFlashPromotionProductRelation> relationList) {

        smsFlashPromotionRelationService.create(relationList);

        return CommonResult.success(null);
    }

    /**
     * 获取管理商品促销信息
     */
    @GetMapping("/{id}")
    public CommonResult findById(@PathVariable Integer id) {

        SmsFlashPromotionProductRelation relation = smsFlashPromotionRelationService.findById(id);

        return CommonResult.success(relation);
    }

}
